//
//  AccountTicketVC.m
//  ImGuider
//
//  Created by 王鹏宇 on 2017/12/7.
//  Copyright © 2017年 AudioCtrip. All rights reserved.
//

#import "AccountTicketVC.h"
#import "AccountTicketListCell.h"
#import "AccountTicketDetailVC.h"
#import "OrderConfirmVC.h"
#import "TicketOrderDetail.h"
#import "TicketOrderVC.h"

@interface AccountTicketVC ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
    @property (weak, nonatomic) IBOutlet NSLayoutConstraint *topSpace;
    
@property (nonatomic, strong)NSMutableArray * dataSource;
@end

@implementation AccountTicketVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self setup];
}


-(void)setup {
    
    self.title = MYLocalizedString(@"TICKET_TITLE", nil);
    self.view.backgroundColor = kBGColor;
   // self.topSpace.constant = 0;
    [self setAutoRowHeight:self.tableView];
    
    [self configEmptyDataTableView:self.tableView emptyImageName:@"暂无优惠劵" describe:MYLocalizedString(@"PUBLIC_NODATA_TICKET", nil) refresh:nil block:nil];
    self.dataHasLoad = YES;
    @weakify(self);
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        @strongify(self);
        
        [self loadData];
    }];
    
    [self.tableView setThemeStyle:ThemeStyleBlack];
    [ActivityIndicatorView showHUDAddedTo:self.view];
    [self loadData];
}


- (void)loadData{
    

    [NetAPIManager getCompeleteTicketOrderBlock:^(NSArray *compeleteTickets, NSError *error) {
        self.dataHasLoad = YES;
        [ActivityIndicatorView hideHUDAddedTo:self.view];
        [self.tableView.mj_header endRefreshing];
        
        self.dataSource = [NSMutableArray arrayWithArray:compeleteTickets];
        [self.tableView reloadData];
    }];
}

#pragma mark  -- UITableViewDelegate,UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.dataSource.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    AccountTicketListCell * cell = [tableView dequeueReusableCellWithIdentifier:@"AccountTicketListCell"];
    
    UploadTicketOrderModel * model = self.dataSource[indexPath.row];
    
    [cell configDataWith:model];
    
    return cell;
}

//- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
//
//    UIView * headerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"headerView"];
//    if (!headerView) {
//        headerView = [[UITableViewHeaderFooterView alloc] initWithReuseIdentifier:@"headerView"];
//        headerView.backgroundColor = [UIColor clearColor];
//    }
//
//    return headerView;
//}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    AccountTicketDetailVC * detailVC = [[AccountTicketDetailVC alloc] init];
    
    UploadTicketOrderModel * model = self.dataSource[indexPath.row];
    
    detailVC.uploadOrderModel = model;
    
    [self.navigationController pushViewController:detailVC animated:YES];
        
    
   
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
